package com.sulent.frame.mp.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * @ClassName PageVo
 * @Description: 分页视图对象
 * @Author Submerge.
 * @Since 2023/9/1 11:52
 * @Version 1.0
 */
public class PageVo<T> {

    private long current;

    private long size;

    private long pages;

    private long total;

    private List<T> records;

    public PageVo(long current, long size, long pages, long total, List<T> records) {
        this.current = current;
        this.size = size;
        this.pages = pages;
        this.total = total;
        this.records = records;
    }

    public long getCurrent() {
        return current;
    }

    public void setCurrent(long current) {
        this.current = current;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public long getPages() {
        return pages;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    /**
     * 将MP的IPage转为PageVo
     * @param page
     * @return
     */
    public PageVo<T> toPageVo(IPage<T> page){
        if (page==null){
            return this;
        }
        this.setCurrent(page.getCurrent());
        this.setSize(page.getSize());
        this.setPages(page.getPages());
        this.setTotal(page.getTotal());
        this.setRecords(page.getRecords());
        return this;
    }
}
